package com.demo;


import android.graphics.Color;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.view.View;

import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.AppCompatActivity;

import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import LecoLi.Item01.ViewPagerFragment;
import LecoLi.Item02.GradleLayoutFragment;

import LecoLi.Item03.LineChartViewPage;


public class MainActivity extends AppCompatActivity {

    private ListView EndList;
    private  ArrayAdapter<String> arrayAdapter;
    private LinearLayout EndLinearLayout;
    private ImageView EndImg;
    private View layout;
    private  DrawerLayout drawer;
    private FrameLayout frameLayout;
    private android.support.v4.app.FragmentManager fm;
    private android.support.v4.app.FragmentTransaction ft;
   String[] values={"我的座驾","我的交通","我的日志","公交查询","我的租车","创意题","退出登录"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView imageView = (ImageView) findViewById(R.id.iv);
        layout = findViewById(R.id.layout);
        frameLayout = (FrameLayout) findViewById(R.id.content_fram_layout); //内容控件绑定
        ListView listView = (ListView) findViewById(R.id.listview);
        listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,values));
        iniEndView();
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

                    layout.setTranslationX(drawerView.getWidth() * slideOffset);

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

        drawer.setScrimColor(Color.TRANSPARENT);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!drawer.isDrawerOpen(GravityCompat.START)) {
                    drawer.openDrawer(GravityCompat.START);

                }

            }
        });
    }
//    ************************************************  右  *****************************************  //
      //右侧滑
    private void iniEndView() {
         EndImg  = (ImageView) findViewById(R.id.iw);
        EndList = (ListView) findViewById(R.id.activity_main_list_end);//右边菜单List
        String[] arrString = getResources().getStringArray(R.array.drawer_list_end);
        arrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,arrString);
        EndList.setAdapter(arrayAdapter);
        iniAtion();
    }
       //动作
    private void iniAtion() {
        EndImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!drawer.isDrawerOpen(GravityCompat.END)) {
                    drawer.openDrawer(GravityCompat.END);
                }
            }
        });

        EndList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i){
                    case 0:
                        sned(new ViewPagerFragment());
                        break;
                    case 1:
                        sned(new GradleLayoutFragment());
                        break;
                    case 2:
                        sned(new LineChartViewPage());
                        break;
                }
            }
        });
    }

    private void sned(Fragment cls){
//        Intent intent = new Intent(MainActivity.this,cls);
//        startActivity(intent);
        ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.content_fram_layout,cls);
        ft.commit();
        drawer.closeDrawers();

    }

}
